import utils from "../../utils/utils";
const http=utils.http;
const star=utils.star;
const sliceTitle=utils.sliceTitle
Page({
    data:{

    },
    onConfirm(e){
        var value=e.detail.value;
        var url=`https://douban.uieee.com/v2/movie/search?q=${value}`;
        http(url,this.handleData);
    },
    handleData(res){
        console.log(res);
        var subjects=res.data.subjects;
        var movies=[];
        subjects.forEach(ele=>{
            var title=sliceTitle(ele.title);
            var id=ele.id;
            var average=ele.rating.average;
            var stars=star(ele.rating.stars);
            var imgUrl=ele.images.large;
            var temp={
                title,
                id,
                average,
                stars,
                imgUrl
            }
            movies.push(temp);
        })
        console.log(movies);
        this.setData({
            movies
        })
    },
    onClick(event){
        var id=event.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/movies/movies-detail/movies-detail?id='+id,
        })
    }
})